[contents] [prev] [next] [top] [bottom] (4 out of 12)

Expression Syntax

This section defines some of the basic expressions that are commonly used in ScriptX programs.

A compound expression is a list of one or more inner-level expressions, enclosed in parentheses. In this respect, parentheses in ScriptX are analogous to braces in C and C++. Since end-of-line tokens can be used as white space, programmers can use parentheses in a variety of styles, just as they do in C. A compound expression is a factor.

compoundExpr	::=	( compoundExprSeq ) 
compoundExprSeq	::=	innerLevelExpr moreExprs 
moreExprs	::=	endOfLine compoundExprSeq 
	|	endOfLine [ moreExprs ]* 
	|	empty 

A call expression is a simple expression that invokes a function or method, supplying a list of arguments that matches the list of parameters in that function or method's calling sequence. (Elsewhere in this grammar, function parameters are sometimes referred to as "argument definitions.") The first token in a call expression must be a factor. This factor must yield a function object, such as a generic function, and is usually the name of a variable holding the function.

The balance of a call expression, if present, supplies a list of arguments. ScriptX supports several different formats for this list, with a choice of commas or spaces as separators.

callExpr	::=	factor paramSequence 
	|	factor ( simpleExpr , paramList ) 
	|	factor ( symbol : factor [ , paramList ] ) 
	|	factor ( ) 
paramSequence	::=	[ symbol : ] factor [ paramSequence ] 
paramList	::=	[ symbol : ] simpleExpr [ , paramList ] 

Only the first two forms of call expression apply to method calls. The first parameter in a method call is always a positional argument; it supplies the name of the object that the method is being called on. A function that is called with no arguments requires a set of empty parentheses, depicted in the fourth form, to identify the expression as a call expression.

In the call expression, and in other ScriptX expressions where a script 
supplies a list of elements to the compiler, ScriptX version 1.0 has a built-in 
limit of 200 items in a list. This restriction is defined syntactically, and applies 
to explicit function arguments, global and local declarations, lists of class and 
instance variables, and lists of expressions in a compound expression sequence.
If a call expression includes both keyword and positional arguments, positional arguments must be supplied first, and in their proper order, followed by rest and keyword arguments. Supplying improper arguments or supplying arguments in the wrong order generates an exception.

The block control expression is a general form that encompasses several types of expression. A block control expression can only be used within a control structure, such as a function, method, or loop. Within a loop, the continue expression is used to immediately resume at the next iteration of the loop. The exit expression is similar to continue, except that evaluation resumes outside the loop, with the next expression in the script. The optional with clause sets the value of the construct upon exit. The return expression exits from the enclosing function or method, and can set the return value, which is otherwise undefined. The final form of block control expression, throw again, is associated with exception handling, and is used only inside guarded code.

blockControlExpr	::=	continue 
	|	exit [ with simpleExpr ] 
	|	return [ simpleExpr ] 
	|	throw again 

An arithmetic expression performs an arithmetic or logical operation on one or more operands. The coercion expression has a similar form. The negation operator and not are unary operators-they operate on a single operand. The compiler allows any simple expression as an operand. This expression must evaluate at run-time to an instance of an appropriate class. For example, the addition operation is defined only for instances of subclasses of Number and String. In some cases, if the second operand is incompatible with the first, it attempts to coerce it. If it is unable to coerce to an appropriate class, it generates an exception.

arithmeticExpr	::=	negOperator simpleExpr 
	|	simpleExpr arithOperator simpleExpr 
	|	simpleExpr compOperator simpleExpr 
	|	simpleExpr contains simpleExpr 
	|	not simpleExpr 
	|	simpleExpr and simpleExpr 
	|	simpleExpr or simpleExpr 
coercionExpr	::=	factor as factor 

Pipe and thread operators provide shorthand equivalents for common operations on objects. The pipe expression is equivalent to an invocation of the pipe generic function, which is implemented on the collection family of classes. The thread operator spawns a new RegularThread object, running the given expression asynchronously.

pipeExpr	::=	| simpleExpr 
threadExpr	::=	simpleExpr & 


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.